<template>
  <div>
      <city-header></city-header>
      <city-search :cities='cities'></city-search>
      <city-list :hotCities='hotCities' :cities='cities' :letters='letters' :letter='letter'></city-list>
      <city-alphabet :letters='letters' @change='letterChanged'></city-alphabet>
  </div>
</template>

<script>
import CityHeader from './components/Header'
import CitySearch from './components/Search'
import CityList from './components/List'
import CityAlphabet from './components/Alphabet'
import axios from 'axios'
export default {
  name: 'City',
  components: {
    CityHeader,
    CitySearch,
    CityList,
    CityAlphabet
  },
  data () {
    return {
      hotCities: [],
      cities: {},
      letter: ''
    }
  },
  computed: {
    letters () {
      const letters = []
      for (let item in this.cities) {
        letters.push(item)
      }
      return letters
    }
  },
  methods: {
    getCityInfo () {
      axios.get('/api/city.json').then((res) => {
        const result = res.data
        if (result.ret && result.data) {
          const data = result.data
          this.cities = data.cities
          this.hotCities = data.hotCities
        }
      })
    },
    letterChanged (letter) {
      this.letter = letter
    }
  },
  mounted () {
    this.getCityInfo()
  }
}
</script>

<style>
</style>
